import pymysql  # 连接数据库，执行sql并返回sql执行结果

def my_db(sql):
    conn = pymysql.connect( host="81.70.83.15",#我的IP地址
    port=3306,   # 不是字符串不需要加引号。
    user='hello123',
    password='jEBCtB7SeCCeMAxH',
    db='hello123',
    charset='utf8')
    cur = conn.cursor(pymysql.cursors.DictCursor)
    cur.execute(sql)
    res = cur.fetchone()  # {'username':'test'}  {}
    cur.close()
    conn.close()
    return res
def my_dball(sql):
    conn = pymysql.connect( host="81.70.83.15",#我的IP地址
    port=3306,   # 不是字符串不需要加引号。
    user='hello123',
    password='jEBCtB7SeCCeMAxH',
    db='hello123',
    charset='utf8')
    cur = conn.cursor(pymysql.cursors.DictCursor)
    print(sql)
    m=cur.execute(sql)
    print("==="+str(m))
    res = cur.fetchall()  # {'username':'test'}  {}
    cur.close()
    conn.close()
    return res
def my_dbupdate(sql):
    conn = pymysql.connect( host="81.70.83.15",#我的IP地址
    port=3306,   # 不是字符串不需要加引号。
    user='hello123',
    password='jEBCtB7SeCCeMAxH',
    db='hello123',
    charset='utf8')
    cur = conn.cursor(pymysql.cursors.DictCursor)
    print(sql)
    m=cur.execute(sql)
    conn.commit()
    print("==="+str(m))
    # res = cur.fetchall()  # {'username':'test'}  {}
    cur.close()
    conn.close()
    return m
def my_dbdelete(sql):
    conn = pymysql.connect( host="81.70.83.15",#我的IP地址
    port=3306,   # 不是字符串不需要加引号。
    user='hello123',
    password='jEBCtB7SeCCeMAxH',
    db='hello123',
    charset='utf8')
    cur = conn.cursor(pymysql.cursors.DictCursor)
    print(sql)
    m=cur.execute(sql)
    conn.commit()
    print("==="+str(m))
    # res = cur.fetchall()  # {'username':'test'}  {}
    cur.close()
    conn.close()
    return m

def my_dbinsert(sql):
    conn = pymysql.connect( host="81.70.83.15",#我的IP地址
    port=3306,   # 不是字符串不需要加引号。
    user='hello123',
    password='jEBCtB7SeCCeMAxH',
    db='hello123',
    charset='utf8')
    cur = conn.cursor(pymysql.cursors.DictCursor)
    print(sql)
    m=cur.execute(sql)
    conn.commit()
    print("==="+str(m))
    # res = cur.fetchall()  # {'username':'test'}  {}
    cur.close()
    conn.close()
    return m

import hashlib


def my_md5(s, salt=''):  # md5加密
    s = s + salt
    news = str(s).encode()
    m = hashlib.md5(news)
    return m.hexdigest()








